extends State




var _player: Player
var _speed_factor: float = 0.5


func _ready() -> void:
    _player = _root.target


func _enter() -> void:
    _root.amt_player.play("move")


func _update(delta: float) -> void:
    var input := Utils.get_input_vec2()
    # 攻击时移动速度减慢50%
    var factor := _speed_factor if _player.is_attacking else 1.0
    _player.velocity = _player.velocity.move_toward(_player.data.speed.value * input * factor, Constant.FRICTION * delta)
    
    if _player.velocity.is_zero_approx():
        switch.emit("Idle")
    elif _player.can_dash() and Input.is_action_just_pressed("dash"):
        switch.emit("Dash")


func _fixed_update(_delta: float) -> void:
    _player.move_and_slide()
